import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

x = np.random.uniform(-3, 3, size=100)
X = x.reshape(-1, 1)
y = 0.5 * x ** 2 + x + 2 + np.random.normal(0, 1, size=100)



liner_regression = LinearRegression()
liner_regression.fit(X, y)
y_predict = liner_regression.predict(X)

X2 = np.hstack([X, X ** 2])
print(X2.shape)
liner_regression.fit(X2, y)
y_predict2 = liner_regression.predict(X2)

plt.plot(x, y_predict, color='green')
plt.plot(np.sort(x), y_predict2[np.argsort(x)], color='red')
plt.scatter(x, y)
plt.show()

